# @file    dispaly_lidar.launch.py
# @brief   dispaly lidar use rviz
# @author  Mr.Wu
# @date    2025-06-06

# Copyright 2025 Mr.Wu

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

#     http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch_ros.actions import LifecycleNode
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch.actions import LogInfo

import lifecycle_msgs.msg
import os


def generate_launch_description():
    # 1,find rviz file absolute path
    package_name="robot_viz"
    package_path=get_package_share_directory(package_name)
    # lidar_rviz_file_path=os.path.join(package_path,"rviz","lidar.rviz")
    lidar_rviz_file_path=os.path.join(package_path,"rviz","vp100.rviz")

    # 2,declare lidar_rviz_file_arg
    lidar_rviz_file_arg=DeclareLaunchArgument(
        "lidar_rviz_file",
        default_value=lidar_rviz_file_path,
        description="Path to the lidar rviz file"
    )

    # 3,start rviz node
    rviz2_node = Node(package='rviz2',
                    executable='rviz2',
                    name='rviz2',
                    arguments=['-d', LaunchConfiguration('lidar_rviz_file')],
                    )

    return LaunchDescription([
        lidar_rviz_file_arg,
        rviz2_node
    ])